package com.shop2cn.iapi.prodstock.testcase;

import java.io.IOException;
import java.util.Arrays;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.shop2cn.iapi.prodstock.parameter.StockOutOnDeliveryBean;
import com.shop2cn.iapi.prodstock.service.StockOutOnDeliveryCall;
import com.shop2cn.iapi.agentproducts.parameter.AddAgentProductBean;
import com.shop2cn.iapi.agentproducts.parameter.ProductDetailsDto;
import com.ymatou.iapi.prodstock.parameter.PreOrderReturnCatalogDto.CatalogListDto;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.annotation.TestSuite;
import com.ymt.utils.tag.P1;
import com.ymttest.business.service.AddAgentProductCallService;
import com.ymttest.business.service.GodfreightmgrService;
import com.ymttest.business.service.Shop2cnStockCallService;
import com.ymttest.utils.AgentUsers;
import com.ymttest.utils.TestDataManager;
/**
*虚拟库存发货扣真实库存Test
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_StockOutOnDelivery{
	private static StockOutOnDeliveryBean stockoutondeliveryBean;
	private static StockOutOnDeliveryCall stockoutondeliveryCall;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("虚拟库存发货扣真实库存Test");
		try {
			GodfreightmgrService.deleteBySellerId(rootUserId);
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	@Before
	public void caseUp() {
		stockoutondeliveryBean=new StockOutOnDeliveryBean();
		stockoutondeliveryCall=new StockOutOnDeliveryCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(stockoutondeliveryCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	
	

	// 渠道商
	private static int rootUserId = AgentUsers.rootUserId;
	private static String rootUserName = "NickautoTest";
	// 渠道商->代理商1
	private static int agentUserId1 = AgentUsers.agentUserId1;
	private static String agentUserName1 = "NickautoTest";
	// vip渠道
	private static int vipRootUserId = AgentUsers.vipRootUserId;
	private static String vipRootUserName = "NickautoTest";
	private static int csId = AgentUsers.csId;
	// vip渠道->代理
	private static int vipAgentUserId1 = AgentUsers.vipAgentUserId1;
	private static String vipAgentUserName1 = "dgsq408897016";
	private static int csId1 = AgentUsers.csId1;

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_ReduceStockListForDelivery_001() {
		Logger.start(true, "真实40件，虚拟30件，发货十件货-----真实30件，虚拟30件");
		try {

			AddAgentProductBean addAgentProductBean = AddAgentProductCallService.initAddAgentProduct(rootUserId,
					rootUserName, true);
			addAgentProductBean.getCatalogList().get(0).setVirtualStock(30);
			addAgentProductBean.getCatalogList().get(0).setStock(40);
			String productId = AddAgentProductCallService.AddAgentProduct(addAgentProductBean);
			ProductDetailsDto productDetailsDto = AddAgentProductCallService.selectProductDetails(rootUserId, productId);
			
			stockoutondeliveryBean.setOrderId(Long.parseLong(TestDataManager.getRandomNum(10)));
			stockoutondeliveryBean.setBizNo(TestDataManager.getRandomNum(10));
			stockoutondeliveryBean.setBuyerId(""+vipAgentUserId1);
			CatalogListDto ca = new CatalogListDto();
			ca.setStockNum(10);
			ca.setCatalogId(productDetailsDto.getCatalogList().get(0).getCatalogId());
			ca.setProductId(productId);
			stockoutondeliveryBean.setCatalogList(Arrays.asList(ca));
			stockoutondeliveryCall.setData(stockoutondeliveryBean);
			stockoutondeliveryCall.callService();			
			Logger.verifyEquals("200", stockoutondeliveryCall.getString("Code"), "验证code");
			
			ProductDetailsDto productDetailsDto2 = AddAgentProductCallService.selectProductDetails(rootUserId, productId);
					
			
			Logger.verifyEquals(productDetailsDto.getCatalogList().get(0).getStock()-10,productDetailsDto2.getCatalogList().get(0).getStock(),"验证库存");
			Logger.verifyEquals(productDetailsDto.getCatalogList().get(0).getRealStock()-10,productDetailsDto2.getCatalogList().get(0).getRealStock(),"验证真实库存");
			Logger.verifyEquals(productDetailsDto.getCatalogList().get(0).getVirtualStock(),productDetailsDto2.getCatalogList().get(0).getVirtualStock(),"验证虚拟库存");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_ReduceStockListForDelivery_002() {
		Logger.start(true, "真实40件，虚拟30件，发货40件货-----真实0件，虚拟30件");
		try {

			AddAgentProductBean addAgentProductBean = AddAgentProductCallService.initAddAgentProduct(rootUserId,
					rootUserName, true);
			addAgentProductBean.getCatalogList().get(0).setVirtualStock(30);
			addAgentProductBean.getCatalogList().get(0).setStock(40);
			String productId = AddAgentProductCallService.AddAgentProduct(addAgentProductBean);
			ProductDetailsDto productDetailsDto = AddAgentProductCallService.selectProductDetails(rootUserId, productId);
			
			stockoutondeliveryBean.setOrderId(Long.parseLong(TestDataManager.getRandomNum(10)));
			stockoutondeliveryBean.setBizNo(TestDataManager.getRandomNum(10));
			stockoutondeliveryBean.setBuyerId(""+vipAgentUserId1);
			CatalogListDto ca = new CatalogListDto();
			ca.setStockNum(40);
			ca.setCatalogId(productDetailsDto.getCatalogList().get(0).getCatalogId());
			ca.setProductId(productId);
			stockoutondeliveryBean.setCatalogList(Arrays.asList(ca));
			stockoutondeliveryCall.setData(stockoutondeliveryBean);
			stockoutondeliveryCall.callService();			
			Logger.verifyEquals("200", stockoutondeliveryCall.getString("Code"), "验证code");
			
			ProductDetailsDto productDetailsDto2 = AddAgentProductCallService.selectProductDetails(rootUserId, productId);
					
			
			Logger.verifyEquals(productDetailsDto.getCatalogList().get(0).getStock()-40,productDetailsDto2.getCatalogList().get(0).getStock(),"验证库存");
			Logger.verifyEquals(productDetailsDto.getCatalogList().get(0).getRealStock()-40,productDetailsDto2.getCatalogList().get(0).getRealStock(),"验证真实库存");
			Logger.verifyEquals(productDetailsDto.getCatalogList().get(0).getVirtualStock(),productDetailsDto2.getCatalogList().get(0).getVirtualStock(),"验证虚拟库存");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_ReduceStockListForDelivery_003() {
		Logger.start(true, "真实40件，虚拟30件，发货50件货-----真实0件，虚拟20件");
		try {

			AddAgentProductBean addAgentProductBean = AddAgentProductCallService.initAddAgentProduct(rootUserId,
					rootUserName, true);
			addAgentProductBean.getCatalogList().get(0).setVirtualStock(30);
			addAgentProductBean.getCatalogList().get(0).setStock(40);
			String productId = AddAgentProductCallService.AddAgentProduct(addAgentProductBean);
			ProductDetailsDto productDetailsDto = AddAgentProductCallService.selectProductDetails(rootUserId, productId);
			
			stockoutondeliveryBean.setOrderId(Long.parseLong(TestDataManager.getRandomNum(10)));
			stockoutondeliveryBean.setBizNo(TestDataManager.getRandomNum(10));
			stockoutondeliveryBean.setBuyerId(""+vipAgentUserId1);
			CatalogListDto ca = new CatalogListDto();
			ca.setStockNum(50);
			ca.setCatalogId(productDetailsDto.getCatalogList().get(0).getCatalogId());
			ca.setProductId(productId);
			stockoutondeliveryBean.setCatalogList(Arrays.asList(ca));
			stockoutondeliveryCall.setData(stockoutondeliveryBean);
			stockoutondeliveryCall.callService();			
			Logger.verifyEquals("400", stockoutondeliveryCall.getString("Code"), "验证code");
			
			ProductDetailsDto productDetailsDto2 = AddAgentProductCallService.selectProductDetails(rootUserId, productId);
			
			Logger.verifyEquals(productDetailsDto.getCatalogList().get(0).getStock(),productDetailsDto2.getCatalogList().get(0).getStock(),"验证库存");
			Logger.verifyEquals(productDetailsDto.getCatalogList().get(0).getRealStock(),productDetailsDto2.getCatalogList().get(0).getRealStock(),"验证真实库存");
			Logger.verifyEquals(productDetailsDto.getCatalogList().get(0).getVirtualStock(),productDetailsDto2.getCatalogList().get(0).getVirtualStock(),"验证虚拟库存");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_ReduceStockListForDelivery_004() {
		Logger.start(true, "真实40件，虚拟30件，发货70件货-----真实0件，虚拟0件");
		try {

			AddAgentProductBean addAgentProductBean = AddAgentProductCallService.initAddAgentProduct(rootUserId,
					rootUserName, true);
			addAgentProductBean.getCatalogList().get(0).setVirtualStock(30);
			addAgentProductBean.getCatalogList().get(0).setStock(40);
			String productId = AddAgentProductCallService.AddAgentProduct(addAgentProductBean);
			ProductDetailsDto productDetailsDto = AddAgentProductCallService.selectProductDetails(rootUserId, productId);
			
			stockoutondeliveryBean.setOrderId(Long.parseLong(TestDataManager.getRandomNum(10)));
			stockoutondeliveryBean.setBizNo(TestDataManager.getRandomNum(10));
			stockoutondeliveryBean.setBuyerId(""+vipAgentUserId1);
			CatalogListDto ca = new CatalogListDto();
			ca.setStockNum(70);
			ca.setCatalogId(productDetailsDto.getCatalogList().get(0).getCatalogId());
			ca.setProductId(productId);
			stockoutondeliveryBean.setCatalogList(Arrays.asList(ca));
			stockoutondeliveryCall.setData(stockoutondeliveryBean);
			stockoutondeliveryCall.callService();			
			Logger.verifyEquals("400", stockoutondeliveryCall.getString("Code"), "验证code");
			
			ProductDetailsDto productDetailsDto2 = AddAgentProductCallService.selectProductDetails(rootUserId, productId);
					
			
			Logger.verifyEquals(productDetailsDto.getCatalogList().get(0).getStock(),productDetailsDto2.getCatalogList().get(0).getStock(),"验证库存");
			Logger.verifyEquals(productDetailsDto.getCatalogList().get(0).getRealStock(),productDetailsDto2.getCatalogList().get(0).getRealStock(),"验证真实库存");
			Logger.verifyEquals(productDetailsDto.getCatalogList().get(0).getVirtualStock(),productDetailsDto2.getCatalogList().get(0).getVirtualStock(),"验证虚拟库存");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_ReduceStockListForDelivery_005() {
		Logger.start(true, "真实40件，虚拟30件，发货80件货-----真实+虚拟不够80，失败");
		try {

			AddAgentProductBean addAgentProductBean = AddAgentProductCallService.initAddAgentProduct(rootUserId,
					rootUserName, true);
			addAgentProductBean.getCatalogList().get(0).setVirtualStock(30);
			addAgentProductBean.getCatalogList().get(0).setStock(40);
			String productId = AddAgentProductCallService.AddAgentProduct(addAgentProductBean);
			ProductDetailsDto productDetailsDto = AddAgentProductCallService.selectProductDetails(rootUserId, productId);
			
			stockoutondeliveryBean.setOrderId(Long.parseLong(TestDataManager.getRandomNum(10)));
			stockoutondeliveryBean.setBizNo(TestDataManager.getRandomNum(10));
			stockoutondeliveryBean.setBuyerId(""+vipAgentUserId1);
			CatalogListDto ca = new CatalogListDto();
			ca.setStockNum(80);
			ca.setCatalogId(productDetailsDto.getCatalogList().get(0).getCatalogId());
			ca.setProductId(productId);
			stockoutondeliveryBean.setCatalogList(Arrays.asList(ca));
			stockoutondeliveryCall.setData(stockoutondeliveryBean);
			stockoutondeliveryCall.callService();			
			Logger.verifyEquals("400", stockoutondeliveryCall.getString("Code"), "验证code");
			
			ProductDetailsDto productDetailsDto2 = AddAgentProductCallService.selectProductDetails(rootUserId, productId);
					
			
			Logger.verifyEquals(productDetailsDto.getCatalogList().get(0).getStock(),productDetailsDto2.getCatalogList().get(0).getStock(),"验证库存");
			Logger.verifyEquals(productDetailsDto.getCatalogList().get(0).getRealStock(),productDetailsDto2.getCatalogList().get(0).getRealStock(),"验证真实库存");
			Logger.verifyEquals(productDetailsDto.getCatalogList().get(0).getVirtualStock(),productDetailsDto2.getCatalogList().get(0).getVirtualStock(),"验证虚拟库存");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_ReduceStockListForDelivery_006() {
		Logger.start(true, "订单号为空，失败");
		try {

			AddAgentProductBean addAgentProductBean = AddAgentProductCallService.initAddAgentProduct(rootUserId,
					rootUserName, true);
			addAgentProductBean.getCatalogList().get(0).setVirtualStock(30);
			addAgentProductBean.getCatalogList().get(0).setStock(40);
			String productId = AddAgentProductCallService.AddAgentProduct(addAgentProductBean);
			ProductDetailsDto productDetailsDto = AddAgentProductCallService.selectProductDetails(rootUserId, productId);
			
			//stockoutondeliveryBean.setOrderId(Long.parseLong(TestDataManager.getRandomNum(10)));
			stockoutondeliveryBean.setBizNo(TestDataManager.getRandomNum(10));
			stockoutondeliveryBean.setBuyerId(""+vipAgentUserId1);
			CatalogListDto ca = new CatalogListDto();
			ca.setStockNum(10);
			ca.setCatalogId(productDetailsDto.getCatalogList().get(0).getCatalogId());
			ca.setProductId(productId);
			stockoutondeliveryBean.setCatalogList(Arrays.asList(ca));
			stockoutondeliveryCall.setData(stockoutondeliveryBean);
			stockoutondeliveryCall.callService();			
			Logger.verifyEquals("200", stockoutondeliveryCall.getString("Code"), "验证code");
			
			ProductDetailsDto productDetailsDto2 = AddAgentProductCallService.selectProductDetails(rootUserId, productId);
					
			
			Logger.verifyEquals(productDetailsDto.getCatalogList().get(0).getStock()-10,productDetailsDto2.getCatalogList().get(0).getStock(),"验证库存");
			Logger.verifyEquals(productDetailsDto.getCatalogList().get(0).getRealStock()-10,productDetailsDto2.getCatalogList().get(0).getRealStock(),"验证真实库存");
			Logger.verifyEquals(productDetailsDto.getCatalogList().get(0).getVirtualStock(),productDetailsDto2.getCatalogList().get(0).getVirtualStock(),"验证虚拟库存");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_ReduceStockListForDelivery_007() {
		Logger.start(true, "买家id为空，失败");
		try {

			AddAgentProductBean addAgentProductBean = AddAgentProductCallService.initAddAgentProduct(rootUserId,
					rootUserName, true);
			addAgentProductBean.getCatalogList().get(0).setVirtualStock(30);
			addAgentProductBean.getCatalogList().get(0).setStock(40);
			String productId = AddAgentProductCallService.AddAgentProduct(addAgentProductBean);
			ProductDetailsDto productDetailsDto = AddAgentProductCallService.selectProductDetails(rootUserId, productId);
			
			stockoutondeliveryBean.setOrderId(Long.parseLong(TestDataManager.getRandomNum(10)));
			stockoutondeliveryBean.setBizNo(TestDataManager.getRandomNum(10));
			//stockoutondeliveryBean.setBuyerId(""+vipAgentUserId1);
			CatalogListDto ca = new CatalogListDto();
			ca.setStockNum(10);
			ca.setCatalogId(productDetailsDto.getCatalogList().get(0).getCatalogId());
			ca.setProductId(productId);
			stockoutondeliveryBean.setCatalogList(Arrays.asList(ca));
			stockoutondeliveryCall.setData(stockoutondeliveryBean);
			stockoutondeliveryCall.callService();			
			Logger.verifyEquals("200", stockoutondeliveryCall.getString("Code"), "验证code");
			
			ProductDetailsDto productDetailsDto2 = AddAgentProductCallService.selectProductDetails(rootUserId, productId);
					
			
			Logger.verifyEquals(productDetailsDto.getCatalogList().get(0).getStock()-10,productDetailsDto2.getCatalogList().get(0).getStock(),"验证库存");
			Logger.verifyEquals(productDetailsDto.getCatalogList().get(0).getRealStock()-10,productDetailsDto2.getCatalogList().get(0).getRealStock(),"验证真实库存");
			Logger.verifyEquals(productDetailsDto.getCatalogList().get(0).getVirtualStock(),productDetailsDto2.getCatalogList().get(0).getVirtualStock(),"验证虚拟库存");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_ReduceStockListForDelivery_008() {
		Logger.start(true, "库存数为负数，失败");
		try {

			AddAgentProductBean addAgentProductBean = AddAgentProductCallService.initAddAgentProduct(rootUserId,
					rootUserName, true);
			addAgentProductBean.getCatalogList().get(0).setVirtualStock(30);
			addAgentProductBean.getCatalogList().get(0).setStock(40);
			String productId = AddAgentProductCallService.AddAgentProduct(addAgentProductBean);
			ProductDetailsDto productDetailsDto = AddAgentProductCallService.selectProductDetails(rootUserId, productId);
			
			stockoutondeliveryBean.setOrderId(Long.parseLong(TestDataManager.getRandomNum(10)));
			stockoutondeliveryBean.setBizNo(TestDataManager.getRandomNum(10));
			stockoutondeliveryBean.setBuyerId(""+vipAgentUserId1);
			CatalogListDto ca = new CatalogListDto();
			ca.setStockNum(-10);
			ca.setCatalogId(productDetailsDto.getCatalogList().get(0).getCatalogId());
			ca.setProductId(productId);
			stockoutondeliveryBean.setCatalogList(Arrays.asList(ca));
			stockoutondeliveryCall.setData(stockoutondeliveryBean);
			stockoutondeliveryCall.callService();			
			Logger.verifyEquals("201", stockoutondeliveryCall.getString("Code"), "验证code");
			
			ProductDetailsDto productDetailsDto2 = AddAgentProductCallService.selectProductDetails(rootUserId, productId);
					
			
			Logger.verifyEquals(productDetailsDto.getCatalogList().get(0).getStock(),productDetailsDto2.getCatalogList().get(0).getStock(),"验证库存");
			Logger.verifyEquals(productDetailsDto.getCatalogList().get(0).getRealStock(),productDetailsDto2.getCatalogList().get(0).getRealStock(),"验证真实库存");
			Logger.verifyEquals(productDetailsDto.getCatalogList().get(0).getVirtualStock(),productDetailsDto2.getCatalogList().get(0).getVirtualStock(),"验证虚拟库存");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_ReduceStockListForDelivery_009() {
		Logger.start(true, "库存数为0失败");
		try {

			AddAgentProductBean addAgentProductBean = AddAgentProductCallService.initAddAgentProduct(rootUserId,
					rootUserName, true);
			addAgentProductBean.getCatalogList().get(0).setVirtualStock(30);
			addAgentProductBean.getCatalogList().get(0).setStock(40);
			String productId = AddAgentProductCallService.AddAgentProduct(addAgentProductBean);
			ProductDetailsDto productDetailsDto = AddAgentProductCallService.selectProductDetails(rootUserId, productId);
			
			stockoutondeliveryBean.setOrderId(Long.parseLong(TestDataManager.getRandomNum(10)));
			stockoutondeliveryBean.setBizNo(TestDataManager.getRandomNum(10));
			stockoutondeliveryBean.setBuyerId(""+vipAgentUserId1);
			CatalogListDto ca = new CatalogListDto();
			ca.setStockNum(0);
			ca.setCatalogId(productDetailsDto.getCatalogList().get(0).getCatalogId());
			ca.setProductId(productId);
			stockoutondeliveryBean.setCatalogList(Arrays.asList(ca));
			stockoutondeliveryCall.setData(stockoutondeliveryBean);
			stockoutondeliveryCall.callService();			
			Logger.verifyEquals("201", stockoutondeliveryCall.getString("Code"), "验证code");
			
			ProductDetailsDto productDetailsDto2 = AddAgentProductCallService.selectProductDetails(rootUserId, productId);
					
			
			Logger.verifyEquals(productDetailsDto.getCatalogList().get(0).getStock(),productDetailsDto2.getCatalogList().get(0).getStock(),"验证库存");
			Logger.verifyEquals(productDetailsDto.getCatalogList().get(0).getRealStock(),productDetailsDto2.getCatalogList().get(0).getRealStock(),"验证真实库存");
			Logger.verifyEquals(productDetailsDto.getCatalogList().get(0).getVirtualStock(),productDetailsDto2.getCatalogList().get(0).getVirtualStock(),"验证虚拟库存");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_ReduceStockListForDelivery_010() {
		Logger.start(true, "商品id为空");
		try {

			AddAgentProductBean addAgentProductBean = AddAgentProductCallService.initAddAgentProduct(rootUserId,
					rootUserName, true);
			addAgentProductBean.getCatalogList().get(0).setVirtualStock(30);
			addAgentProductBean.getCatalogList().get(0).setStock(40);
			String productId = AddAgentProductCallService.AddAgentProduct(addAgentProductBean);
			ProductDetailsDto productDetailsDto = AddAgentProductCallService.selectProductDetails(rootUserId, productId);
			
			stockoutondeliveryBean.setOrderId(Long.parseLong(TestDataManager.getRandomNum(10)));
			stockoutondeliveryBean.setBizNo(TestDataManager.getRandomNum(10));
			stockoutondeliveryBean.setBuyerId(""+vipAgentUserId1);
			CatalogListDto ca = new CatalogListDto();
			ca.setStockNum(10);
			ca.setCatalogId(productDetailsDto.getCatalogList().get(0).getCatalogId());
			//ca.setProductId(productId);
			stockoutondeliveryBean.setCatalogList(Arrays.asList(ca));
			stockoutondeliveryCall.setData(stockoutondeliveryBean);
			stockoutondeliveryCall.callService();			
			Logger.verifyEquals("201", stockoutondeliveryCall.getString("Code"), "验证code");
			
			ProductDetailsDto productDetailsDto2 = AddAgentProductCallService.selectProductDetails(rootUserId, productId);
					
			
			Logger.verifyEquals(productDetailsDto.getCatalogList().get(0).getStock(),productDetailsDto2.getCatalogList().get(0).getStock(),"验证库存");
			Logger.verifyEquals(productDetailsDto.getCatalogList().get(0).getRealStock(),productDetailsDto2.getCatalogList().get(0).getRealStock(),"验证真实库存");
			Logger.verifyEquals(productDetailsDto.getCatalogList().get(0).getVirtualStock(),productDetailsDto2.getCatalogList().get(0).getVirtualStock(),"验证虚拟库存");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_ReduceStockListForDelivery_011() {
		Logger.start(true, "商品规格为空");
		try {

			AddAgentProductBean addAgentProductBean = AddAgentProductCallService.initAddAgentProduct(rootUserId,
					rootUserName, true);
			addAgentProductBean.getCatalogList().get(0).setVirtualStock(30);
			addAgentProductBean.getCatalogList().get(0).setStock(40);
			String productId = AddAgentProductCallService.AddAgentProduct(addAgentProductBean);
			ProductDetailsDto productDetailsDto = AddAgentProductCallService.selectProductDetails(rootUserId, productId);
			
			stockoutondeliveryBean.setOrderId(Long.parseLong(TestDataManager.getRandomNum(10)));
			stockoutondeliveryBean.setBizNo(TestDataManager.getRandomNum(10));
			stockoutondeliveryBean.setBuyerId(""+vipAgentUserId1);
			CatalogListDto ca = new CatalogListDto();
			ca.setStockNum(10);
			//ca.setCatalogId(productDetailsDto.getCatalogList().get(0).getCatalogId());
			ca.setProductId(productId);
			stockoutondeliveryBean.setCatalogList(Arrays.asList(ca));
			stockoutondeliveryCall.setData(stockoutondeliveryBean);
			stockoutondeliveryCall.callService();			
			Logger.verifyEquals("201", stockoutondeliveryCall.getString("Code"), "验证code");
			
			ProductDetailsDto productDetailsDto2 = AddAgentProductCallService.selectProductDetails(rootUserId, productId);
					
			
			Logger.verifyEquals(productDetailsDto.getCatalogList().get(0).getStock(),productDetailsDto2.getCatalogList().get(0).getStock(),"验证库存");
			Logger.verifyEquals(productDetailsDto.getCatalogList().get(0).getRealStock(),productDetailsDto2.getCatalogList().get(0).getRealStock(),"验证真实库存");
			Logger.verifyEquals(productDetailsDto.getCatalogList().get(0).getVirtualStock(),productDetailsDto2.getCatalogList().get(0).getVirtualStock(),"验证虚拟库存");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_ReduceStockListForDelivery_012() {
		Logger.start(true, "商品id与规格id不匹配，失败");
		try {

			AddAgentProductBean addAgentProductBean = AddAgentProductCallService.initAddAgentProduct(rootUserId,
					rootUserName, true);
			addAgentProductBean.getCatalogList().get(0).setVirtualStock(30);
			addAgentProductBean.getCatalogList().get(0).setStock(40);
			String productId = AddAgentProductCallService.AddAgentProduct(addAgentProductBean);
			ProductDetailsDto productDetailsDto = AddAgentProductCallService.selectProductDetails(rootUserId, productId);
			
			
			AddAgentProductBean addAgentProductBean1 = AddAgentProductCallService.initAddAgentProduct(rootUserId,
					rootUserName, true);
			addAgentProductBean1.getCatalogList().get(0).setVirtualStock(30);
			addAgentProductBean1.getCatalogList().get(0).setStock(40);
			String productId1 = AddAgentProductCallService.AddAgentProduct(addAgentProductBean1);
			ProductDetailsDto productDetails = AddAgentProductCallService.selectProductDetails(rootUserId, productId1);
			
			
			stockoutondeliveryBean.setOrderId(Long.parseLong(TestDataManager.getRandomNum(10)));
			stockoutondeliveryBean.setBizNo(TestDataManager.getRandomNum(10));
			stockoutondeliveryBean.setBuyerId(""+vipAgentUserId1);
			CatalogListDto ca = new CatalogListDto();
			ca.setStockNum(10);
			ca.setCatalogId(productDetails.getCatalogList().get(0).getCatalogId());
			ca.setProductId(productId);
			stockoutondeliveryBean.setCatalogList(Arrays.asList(ca));
			stockoutondeliveryCall.setData(stockoutondeliveryBean);
			stockoutondeliveryCall.callService();			
			Logger.verifyEquals("200", stockoutondeliveryCall.getString("Code"), "验证code");
			
			ProductDetailsDto productDetailsDto2 = AddAgentProductCallService.selectProductDetails(rootUserId, productId);
			Logger.verifyEquals(productDetailsDto.getCatalogList().get(0).getStock(),productDetailsDto2.getCatalogList().get(0).getStock(),"验证库存");
			Logger.verifyEquals(productDetailsDto.getCatalogList().get(0).getRealStock(),productDetailsDto2.getCatalogList().get(0).getRealStock(),"验证真实库存");
		

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_ReduceStockListForDelivery_0013() {
		Logger.start(true, "幂等---真实40件，虚拟30件，发货十件货-----真实30件，虚拟30件");
		try {

			AddAgentProductBean addAgentProductBean = AddAgentProductCallService.initAddAgentProduct(rootUserId,
					rootUserName, true);
			addAgentProductBean.getCatalogList().get(0).setVirtualStock(30);
			addAgentProductBean.getCatalogList().get(0).setStock(40);
			String productId = AddAgentProductCallService.AddAgentProduct(addAgentProductBean);
			ProductDetailsDto productDetailsDto = AddAgentProductCallService.selectProductDetails(rootUserId, productId);
			
			stockoutondeliveryBean.setOrderId(Long.parseLong(TestDataManager.getRandomNum(10)));
			stockoutondeliveryBean.setBizNo(TestDataManager.getRandomNum(10));
			stockoutondeliveryBean.setBuyerId(""+vipAgentUserId1);
			CatalogListDto ca = new CatalogListDto();
			ca.setStockNum(10);
			ca.setCatalogId(productDetailsDto.getCatalogList().get(0).getCatalogId());
			ca.setProductId(productId);
			stockoutondeliveryBean.setCatalogList(Arrays.asList(ca));
			stockoutondeliveryCall.setData(stockoutondeliveryBean);
			StockOutOnDeliveryCall call1= stockoutondeliveryCall;
			stockoutondeliveryCall.callService();			
			Logger.verifyEquals("200", stockoutondeliveryCall.getString("Code"), "验证code");
			Logger.verifyEquals("200", call1.getString("Code"), "验证code");
			
			ProductDetailsDto productDetailsDto2 = AddAgentProductCallService.selectProductDetails(rootUserId, productId);
					
			
			Logger.verifyEquals(productDetailsDto.getCatalogList().get(0).getStock()-10,productDetailsDto2.getCatalogList().get(0).getStock(),"验证库存");
			Logger.verifyEquals(productDetailsDto.getCatalogList().get(0).getRealStock()-10,productDetailsDto2.getCatalogList().get(0).getRealStock(),"验证真实库存");
			Logger.verifyEquals(productDetailsDto.getCatalogList().get(0).getVirtualStock(),productDetailsDto2.getCatalogList().get(0).getVirtualStock(),"验证虚拟库存");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_ReduceStockListForDelivery_0014() {
		Logger.start(true, "下单虚拟库存十件，然后进行发货");
		try {

			AddAgentProductBean addAgentProductBean = AddAgentProductCallService.initAddAgentProduct(rootUserId,
					rootUserName, true);
			addAgentProductBean.getCatalogList().get(0).setVirtualStock(30);
			addAgentProductBean.getCatalogList().get(0).setStock(0);
			String productId = AddAgentProductCallService.AddAgentProduct(addAgentProductBean);
			ProductDetailsDto productDetailsDto = AddAgentProductCallService.selectProductDetails(rootUserId, productId);
			//下单虚拟十件
			String catalogId = productDetailsDto.getCatalogList().get(0).getCatalogId();
			long order = Shop2cnStockCallService.InitReduceStockForOrder(rootUserId,catalogId,productId,10);
			//手动入库二十件
			Shop2cnStockCallService.prodstockstockIn(rootUserId,productId,20);
			
			//发货十件
			stockoutondeliveryBean.setOrderId(order);
			stockoutondeliveryBean.setBizNo(TestDataManager.getRandomNum(10));
			stockoutondeliveryBean.setBuyerId(""+vipAgentUserId1);
			CatalogListDto ca = new CatalogListDto();
			ca.setStockNum(10);
			ca.setCatalogId(catalogId);
			ca.setProductId(productId);
			stockoutondeliveryBean.setCatalogList(Arrays.asList(ca));
			stockoutondeliveryCall.setData(stockoutondeliveryBean);
			stockoutondeliveryCall.callService();			
			Logger.verifyEquals("200", stockoutondeliveryCall.getString("Code"), "验证code");
			
			ProductDetailsDto productDetailsDto2 = AddAgentProductCallService.selectProductDetails(rootUserId, productId);
			
			Logger.verifyEquals(30,productDetailsDto2.getCatalogList().get(0).getStock(),"验证库存");
			Logger.verifyEquals(10,productDetailsDto2.getCatalogList().get(0).getRealStock(),"验证真实库存");
			Logger.verifyEquals(20,productDetailsDto2.getCatalogList().get(0).getVirtualStock(),"验证虚拟库存");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
}